package com.leizhi.demo.onvif.discovery;

import com.leizhi.demo.onvif.utils.JacksonUtil;
import jakarta.xml.ws.BindingProvider;
import org.onvif.ver10.device.wsdl.Device;
import org.onvif.ver10.device.wsdl.DeviceService;
import org.onvif.ver10.schema.SystemDateTime;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * @Description
 * @Version ${MavenProject.version}
 * @Author leizhi
 * @Date 2025/7/12 15:26
 */
public class Test {

    public static void main(String[] args) throws MalformedURLException {
        URL wsdlUrl = Test.class.getClassLoader().getResource("wsdl/devicemgmt.wsdl");
        DeviceService deviceService = new DeviceService(wsdlUrl);
        Device device = deviceService.getDevicePort();

        String deviceUrl = "http://192.168.1.169/onvif/device_service";
        ((BindingProvider) device).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, deviceUrl);
        ((BindingProvider) device).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "admin");
        ((BindingProvider) device).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "123456");

        SystemDateTime dateAndTime = device.getSystemDateAndTime();
        System.out.println("设备能力: " + JacksonUtil.toJson(dateAndTime.getUTCDateTime()));
    }

}
